#ifndef PARSER_H_
#define PARSER_H_

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <string.h>
#include <map>
#include <vector>
#include <stdio.h>

#include "Material.h"

const int INIT_MOCP_ID = 1001;

class Material;

class Parser
{
private:

    /* file stream, input */
    std::ifstream _file;

    /* file stream, output */
    std::ofstream _out;

    /* MOCP material out */
    char* _mocp_m_file;

    /* file name, input */
    char* _file_name;

    /* file name, output */
    char* _file_out_name;

    datfmt _fmt;

    /* container to save the key words */
    // static std::map<std::string, std::string> _material_keys;
    std::map<std::string, Material*> _materials;
    std::map<std::string, std::string> _blocks;


    /* pivate functions */
    void setName(const char* file_name);

public:

    Parser();
    Parser(const char* file_name);

    virtual ~Parser();

    void setFMT(datfmt fmt) { _fmt = fmt; }

    void setMOCPfile(char* name) { _mocp_m_file = name; }

    /* open text file */
    void open(const char* file_name);

    /* write = "write" set the name of outpute file */
    void open(const char* name, const char* write);

    /* parse the text file according the keys */
    void parse();

    void findBlock(std::string &full, const char* start_label, const char* end_label);

    void parseMaterials();

    /* get the name of sub-blocks */
    std::string getSubName(std::string &block);

    std::string getValue(const char* key, std::string &block);

    /* convert a string which contains number(s) to double float kind of vector */
    std::vector<double> str2ds(std::string string);

    /* conver a string which contains number(s) to integer kind of vector */
    std::vector<int> str2is(std::string string);

    /* convert a string which contais a string and spaces to a string which do NOT
       contains spaces
    */
    std::string str2str(std::string string);

    void write();

    void writeMOCP();
};


#endif /* PARSER_H_ */
